package com.wtw;

import com.entity.UserEntity;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import java.util.ArrayList;
import java.util.List;

/**
 * <strong>Title : <br></strong>
 * <strong>Package : <br></strong>
 * <strong>Description : </strong><br>
 * <strong>Create on : 2018/6/20<br></strong>
 * <p>
 *
 * @author tengwei.wang<br>
 * @version <strong>v1.0.0</strong><br>
 *          <br>
 *          <strong>修改历史:</strong><br>
 *          修改人 | 修改日期 | 修改描述<br>
 *          -------------------------------------------<br>
 *          <br>
 *          <br>
 */

@Controller
public class TestThymeleaf {

    @RequestMapping("thymeTest")
    public ModelAndView index(Model model){
        model.addAttribute("host", "http://blog.didispace.com");
        return new ModelAndView("indexOne","userModel",model);
    }

    /**
     * 在springboot框架中返回界面不需要像ssm在配置文件里面配置；下面是两种返回方式
     * （1） ModelAndView modelAndView = new ModelAndView();
             modelAndView.addObject("name", "xxx");
             modelAndView.setViewName("/user/index");
            return modelAndView;
        （2）String retVal = "user/index";
             User user = new User();
             user.setName("XXX");
             model.addAttribute("currentUser", user);
             return retVal;
     * @param model
     * @return
     */
    @RequestMapping("thymeTest2")
    public String index2(Model model){
        List<UserEntity> list = new ArrayList<>();
        UserEntity userEntity = new UserEntity();
        userEntity.setName("11111");
        UserEntity userEntity2 = new UserEntity();
        userEntity2.setName("22222");
        UserEntity userEntity3 = new UserEntity();
        userEntity3.setName("33333");
        list.add(userEntity);
        list.add(userEntity2);
        list.add(userEntity3);
        model.addAttribute("list",list);
        return "indexTwo";
    }
}
